#include "Game.h"
#include "Frame.h"

#include "BaseObject.h"

#include "../wrappers/CSGD_TextureManager.h"
#include "../wrappers/CSGD_EventSystem.h"

#include <cassert>


CFrame::CFrame(void)
{
	m_nFrameHeight = 0;
	m_nFrameWidth  = 0;
	m_fDuration	   = 0.0f;
	m_bCurrFrame   = false;
	m_nImageID	   = -1;
}


CFrame::~CFrame(void)
{
}


void CFrame::UpdateFrame( CBaseObject* pOwner )
{
	if( m_fCurrTime < m_fDuration )
	{
		m_fCurrTime += CGame::GetInstance()->GetElapsedTime();
	}
}


void CFrame::RenderFrame( CBaseObject* pOwner )
{
	assert( m_nImageID != -1 && "CFrame::RenderFrame - bad image ID" );
	
	
	//CSGD_TextureManager::GetInstance()->Draw(
	//	m_nImageID,
	//	,
	//	,
	//	1.0f,1.0f, &m_rFrameRect
	//	);
						
}


bool CFrame::CheckDefenseCollision( RECT* rAttackRect )
{
	RECT rOverlap;
	vector< RECT >::iterator rectIter = m_DefenseRects.begin();
	for( ; rectIter != m_DefenseRects.end(); ++rectIter )
	{
		if( IntersectRect( &rOverlap, &(*rectIter), rAttackRect ) == TRUE )
		{
			return true;
		}
	}

	return false;
}


bool CFrame::CheckAttackCollision( RECT* rDefenseRect )
{
	RECT rOverlap;
	vector< RECT >::iterator rectIter = m_AttackRects.begin();
	for( ; rectIter != m_AttackRects.end(); ++rectIter )
	{
		if( IntersectRect( &rOverlap, &(*rectIter), rDefenseRect ) == TRUE )
		{
			return true;
		}
	}

	return false;
	
}


bool CFrame::CheckFrameCollision( CFrame* pFrame )
{
	RECT rOverlap;

	if( IntersectRect( &rOverlap, &m_rBaseRect, &pFrame->m_rBaseRect ) == TRUE )
	{
		vector< RECT >::iterator rectIter = m_AttackRects.begin();
		for( ; rectIter != m_AttackRects.end(); ++rectIter )
		{
			if( pFrame->CheckDefenseCollision( &(*rectIter) ) == true )
				return true;
		}
	}
	return false;
}


void CFrame::SetAnchorPoint( float fX, float fY )
{
	m_tAnchorPoint.fX = fX;
	m_tAnchorPoint.fY = fY;
}


void CFrame::AddAttackRect( RECT rAttack )
{

}